//========================================================//
// Cryptography big integer clasess                       //
// Author: Kozlov Dmitry aka LandFox kozlov@ccfit.nsu.ru  //
// NSU FIT September - October 2004                       //
//========================================================//

#ifndef _CRYPTINT_H_
#define _CRYPTINT_H_

//#include "C:\\Documents and Settings\\sfaktorovich\\My Documents\\remoteconsole2\\vld.h"

#include <stdio.h>
#include <iostream>
#include "../common/exception.h"

using namespace std;

#ifdef _WIN32
	typedef unsigned __int64 qword;
#else
	typedef unsigned long long qword;
#endif

class cCryptIntException : public cException {
	public:
		cCryptIntException(const char * mesg) : cException(mesg) {}
};

static const cCryptIntException EXC_WrongSize("Wrong number size.");
static const cCryptIntException EXC_WrongCharacter("Wrong character.");

class cCryptIntData {
	friend ostream& operator << (ostream& os,const cCryptIntData&);
	friend class cCryptIntManager;

	private:
		unsigned char data[128];

	public:
		cCryptIntData(const char * data, int length,bool acsii = false);
		unsigned char * getData(void) const {
			return (unsigned char *)data;
		}
};

class cCryptIntManager {

	private:
		unsigned char * mode;
		unsigned char shift;//how much nee left shift divide
		unsigned long mode_length;
		inline long compare(unsigned long * v1,unsigned long * v2);//not need
		void Mode(unsigned char * buf);

	public:
		cCryptIntManager();
		cCryptIntManager(const cCryptIntData& mod);//c = mod
		~cCryptIntManager();
		void Mul(cCryptIntData& a,const cCryptIntData& b);//a = (a * b) mod c
		void setMode(const cCryptIntData& data);//c = data
		void exp(cCryptIntData& x,const cCryptIntData& y);//x = x^y mod c
};

ostream& operator << (ostream& os,const cCryptIntData&);

#endif
